import { toLoopCount } from "./utils";
import EventEmitter from 'eventemitter3'

type FrameSegment = [number, number?];

export type LoopType = number | boolean

interface AnimateEvents {
    error: [Error]
    ready: []
    start: []
    pause: []
    stop: []
    loopComplete: [number]
    complete: []
}

abstract class Controller extends EventEmitter<AnimateEvents> {
    _loop: number;
    _speed: number;

    constructor() {
        super();
        this._loop = 1;
        this._speed = 1;
    }

    setLoop(loop: LoopType): this {
        this._loop = toLoopCount(loop);
        return this;
    }

    setSpeed(speed: number): this {
        this._speed = speed;
        return this;
    }

    abstract start(): Promise<void>;
    abstract stop(): this;
    abstract pause(): this;
    abstract gotoAndPlay(value: number): this;
    abstract gotoAndStop(value: number): this;
    abstract playSegments(segment: FrameSegment, loop?: LoopType, speed?: number): this;
}

export { Controller }